package net.jforum;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.jforum.dao.DataAccessDriver;
import net.jforum.dao.TopicDAO;
import net.jforum.dao.UserFriendDAO;
import net.jforum.dao.generic.GenericUserFriendDAO;
import net.jforum.entities.Topic;
import net.jforum.repository.SummaryRepository;
import net.jforum.util.CommonUtil;
import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;

/**
 * @ author  张洋 jackson.zhang@ericsson.com
 * @ version 创建时间 ：Aug 18, 2010  11:52:51 AM
 * @ description : 
 */
class TestThread extends Thread{
	public void run(){
		TestTools.testThread();
	}
}
public class TestTools {
	private static String TEST="test";

	 
	 public  static boolean addFriend(int userId,int friendId){
		 UserFriendDAO dao = DataAccessDriver.getInstance().newUserFriendDAO();
		 return dao.addOneRelationByIds(userId,friendId);
	 }
	 
	 public static void testThread(){
		 synchronized(TEST){
			 System.out.println(System.currentTimeMillis()+" start..");
			 try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(System.currentTimeMillis()+"end...");
		 }
	 }
	 public static void test(){
		 UserFriendDAO dao = DataAccessDriver.getInstance().newUserFriendDAO();
		 boolean result=dao.addOneRelationByIds(15,16);
		 boolean result1=dao.addOneRelationByIds(15,14);
		 boolean result2=dao.addOneRelationByIds(15,13);
		 boolean result3=dao.addOneRelationByIds(15,12);
		 boolean result7=dao.isFriendAdded(15,16);
		 boolean result8=dao.isFriendAdded(15,17);
		 List friends=dao.selectAllFriendsByUserId(15);
		 dao.deleteByUserAndFriend(15, 17);
		 System.out.println("over");
		 
	 }
	 public static void split(String content){
		 String str=content;
		 List<String> list=new ArrayList();
		 while(str.trim().length()>0)
		 {
			  int index=str.trim().indexOf(" ");
			  if(index!=-1){
			  list.add(str.substring(0, index));
			 str=str.substring(index).trim();}
			 
		 }
		 for(String s:list){
		 System.out.println(s);
		 }
		 
//		 String[] str=content.split(" ");
//		 List list=new ArrayList();
//		 for(String s:str){
//			 if(!"".equals(s))
//			 System.out.print(s+"/");
//			 list.add(s);
//		 }
//		 System.out.println(list.size());
	 }
	 
	 
	 public static String split(String input ,String separator){
		 System.out.println(System.currentTimeMillis());
		 String inputString =input.trim();
		 String result="%";
		 while(inputString.length()!=0){
			 int index=inputString.indexOf(" ");
			 if(index==-1){
				result=result+inputString+"%";
				 System.out.println(inputString);
				 break;
			 }
			 String s=inputString.substring(0,index);
			result=result+s+"%";
			 inputString=inputString.substring(index,inputString.length()).trim();
			 
		 }
		 System.out.println(result);
		 System.out.println(System.currentTimeMillis());
		 return result;
	 }
	 public static void main(String[] args){
		 
		 CommonUtil.splitSearchKeyword(" a  adf a", "%");
		 
//		 System.out.println(CommonUtil.getDateMonthlyBefore(new Date()));
//		 System.out.println(CommonUtil.getDateWeekBefore(new Date()));
//		Date date=new Date();
//		System.out.println(date.getTime());
//		long t=date.getTime()-1000*60*60*24*10;
//		System.out.println(t);
//		 
//		Calendar myDate=Calendar.getInstance();  
//		myDate.setTime(new Date());   //设置时间为当前时间   
//		myDate.add(Calendar.MONTH, -1); //月份减1 
//		System.out.println(myDate.getTime());
//		
//		
// 		List<Topic> list=SummaryRepository.loadWeeklyTopicsByViewsByLimit();
//		for(Topic t1:list){
// 			System.out.println(t1.getId()+":"+t1.getTitle()+"," );
// 		}
		 
	 }
	 public static void test(String[] args){
//		 TestThread t1=new TestThread();
//		 TestThread t2=new TestThread();
//		 TestThread t3=new TestThread();
//		 t1.start();
//		 t2.start();
//		 t3.start();
		 
		 List<Topic> weeklylist=SummaryRepository.loadWeeklyTopicsByRepliesByLimit(SystemGlobals.getIntValue(ConfigKeys.WEEKLY_SUMMARY_TOPICS_CACHE_SIZE));
		 List<Topic> monthlyList=SummaryRepository.loadMonthlyTopicsByRepliesByLimit(SystemGlobals.getIntValue(ConfigKeys.MONTHLY_SUMMARY_TOPICS_CACHE_SIZE));
		 System.out.println("Weekly summary: ");
		 for(Topic t:weeklylist){
		   System.out.print(t.getId()+" ");	 
		 }
		 System.out.println("Monthly summary: ");
		 for(Topic t:monthlyList){
		   System.out.print(t.getId()+" ");	 
		 }
		 
			List<Topic> list=SummaryRepository.loadWeeklyTopicsByViewsByLimit();
			for(Topic t1:list){
				System.out.println(t1.getId()+":"+t1.getTitle()+"," );
			}
		 
//		 long time=System.currentTimeMillis();
//		 System.out.println(time);
//		 System.out.println(25%10);
//		 System.out.println(time%(24*60*60*1000));
//		 System.out.println(time-time%(24*60*60*1000));
//		System.out.println(new Date(time-time%(24*60*60*1000) ));
//		Date date=new Date();
//		date.setHours(0);
//		date.setMinutes(0);
//		date.setSeconds(0);
//		System.out.println(date);
//		 
////		 split("发生地     你    你你你你  ");
//		 String m="&#x5C0A;&#x656C;&#x7684;&#x7528;&#x6237;,&#x6B22;&#x8FCE;&#x6CE8;&#x518C;&#x6211;&#x4EEC;&#x7684;&#x7F51;&#x7AD9;&#xFF0C;&#x9996;&#x5148;&#x8BF7;&#x60A8;&#x586B;&#x5199;&#x5B8C;&#x6574;&#x60A8;&#x7684;&#x8BE6;&#x7EC6;&#x8D44;&#x6599;&#xFF0C;&#x8BF7;&#x4F60;&#x9075;&#x5FAA;&#x6211;&#x4EEC;&#x7F51;&#x7AD9;&#x7684;&#x89C4;&#x5219;&#x53D1;&#x5E16;&#xFF0C;&#x8C22;&#x8C22;!";
//		 
//		 String t=";"+m;
//		 System.out.println(change(t));
//		 Date date=new Date();
//		 date.setHours(0);
//		 date.setMinutes(0);
//		 date.setSeconds(0);
//		 Date lastDate=new Date();
//		 lastDate.setMinutes(lastDate.getMinutes()+1);
//		 int count=DataAccessDriver.getInstance().newSummaryDAO().countTodayTopicsByForum(date,lastDate,2);
//	   System.out.println("count:"+count);
//	 Map map=  (Map)SummaryRepository.loadCountTodayTopicsAll();
//	 if(!map.isEmpty()){
//	 Set s= map.keySet();
//	  Iterator itr= s.iterator();
//	  while(itr.hasNext()){
//		  String key=(String)itr.next();
//		  System.out.println("key= "+key+" ; value="+map.get(key));
//	  }
//	  for(int i=0;i<30;i++){
//		  System.out.println("forumId= "+i+" count= "+SummaryRepository.getCountTodayByForumId(i));
//	  }
//	 }
//	 
	 }
	 public static String change(String s){
		 String m=s.trim().replaceAll("&#x", "\\u").replace(';', '\\');
		m=m.substring(0, m.length()-1);
		return m;
		 
		 
	 }

	
}
